/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.ExtInfo;
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CustomerManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.thread.LuceneThread;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONArray;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class AddAppPeople extends AbstractAction
/*     */ {
/*  30 */   private static Logger logger = Logger.getLogger(AddAppPeople.class
/*  31 */     .getName());
/*     */ 
/*  33 */   private String indexPath = null;
/*     */ 
/*     */   public AddAppPeople(AbstractHttpServlet servlet, String indexPath) {
/*  36 */     super(servlet);
/*  37 */     this.indexPath = indexPath;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  43 */     User user = super.getLoginUser(request);
/*     */ 
/*  45 */     String companyName = request.getParameter("companyName");
/*  46 */     String peopleName = request.getParameter("peopleName");
/*  47 */     String peopleTitle = request.getParameter("title");
/*     */ 
/*  49 */     String peopleNote = request.getParameter("note");
/*     */ 
/*  51 */     int visible = Util.str2Int(request.getParameter("visible"));
/*  52 */     String permissionsId = request.getParameter("permissionsId");
/*  53 */     String tagIds = request.getParameter("tagIds");
/*  54 */     int categoryId = Util.str2Int(request.getParameter("categoryId"));
/*     */ 
/*  56 */     if (1 == visible) {
/*  57 */       permissionsId = "";
/*     */     }
/*     */ 
/*  60 */     String extInfo = request.getParameter("extInfo");
/*  61 */     List extInfos = new ArrayList();
/*     */     try
/*     */     {
/*  64 */       JSONArray array = JSONArray.fromObject(extInfo);
/*  65 */       if ((array != null) && (array.size() > 0))
/*  66 */         for (int i = 0; i < array.size(); i++) {
/*  67 */           ExtInfo item = new ExtInfo();
/*  68 */           item.type = Util.getJSONIntValue(array.getJSONObject(i), 
/*  69 */             "type");
/*  70 */           item.info1 = Util.getJSONStringValue(
/*  71 */             array.getJSONObject(i), "info1");
/*  72 */           item.info2 = Util.getJSONStringValue(
/*  73 */             array.getJSONObject(i), "info2");
/*  74 */           item.info3 = Util.getJSONStringValue(
/*  75 */             array.getJSONObject(i), "info3");
/*  76 */           item.info4 = Util.getJSONStringValue(
/*  77 */             array.getJSONObject(i), "info4");
/*  78 */           if ((item.info1 != null) && (item.info1.trim().length() != 0))
/*     */           {
/*  81 */             extInfos.add(item);
/*     */           }
/*     */         }
/*     */     } catch (Exception e) {
/*  85 */       logger.warn("add people info failed", e);
/*     */     }
/*     */ 
/*  88 */     CustomerManager manager = new CustomerManager();
/*     */ 
/*  90 */     int id = manager.addPeople(companyName, peopleName, peopleTitle, 
/*  91 */       categoryId, peopleNote, visible, permissionsId, "", "", tagIds, 
/*  92 */       extInfos, user.userId, user.companyId);
/*     */ 
/*  94 */     response.setContentType("text/html;charset=utf-8");
/*  95 */     PrintWriter out = response.getWriter();
/*  96 */     JSONObject jsonObject = new JSONObject();
/*  97 */     if (id <= 0) {
/*  98 */       jsonObject.put("error", "1");
/*  99 */       jsonObject.put("msg", "客户信息创建失败");
/*     */     } else {
/* 101 */       jsonObject.put("error", "0");
/* 102 */       jsonObject.put("customerId", Integer.valueOf(id));
/*     */ 
/* 105 */       new LuceneThread(this.indexPath, false).start();
/*     */     }
/* 107 */     out.println(jsonObject);
/* 108 */     out.flush();
/* 109 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.AddAppPeople
 * JD-Core Version:    0.6.1
 */